# -*- coding:utf8 -*- #
# -----------------------------------------------------------------------------------
# ProjectName:   mqtt_connection
# FileName:     read_json
# Author:
# Datetime:    2022/4/6 14:29
# Description：
# -----------------------------------------------------------------------------------
import json

from common.util.configUtil.configUtil import ConfigUtil


class JsonUtil:
    def __init__(self):

        self.config = ConfigUtil()

    def read_sql(self, sql_key) -> str:
        """
                    ;True：线上环境
                    ;False：测试环境
                """
        sql_path = self.config.get_sql_json_path()
        with open(sql_path, encoding="utf-8") as data:
            sql_data = json.load(data)
            if self.config.get_database_status() is True:
                return sql_data["Pro"][sql_key]
            else:
                return sql_data["Test"][sql_key]

    def read_connack(self, code) -> str:
        code = str(code)
        connack_path = self.config.get_connackData_path()
        with open(connack_path, encoding="utf8") as data:
            json_data = json.load(data)
            list_k = []
            for k, v in json_data.items():
                list_k.append(k)
            if code in list_k:
                return json_data[code]

    # def read_Equipmen(self, key="deviceName", value=1, mode="r"):
    #     """
    #     :param key: key值
    #     :param value:value值
    #     :param mode: 读写方式
    #     :return:
    #     1 、mode = r 时,仅读取json文件中的内容
    #     2 、mode = w 时,将组合有功参数写入json中
    #     """
    #     equipmen_path = self.file_path.get_Equipment_Data_path()
    #     if mode == "r":
    #         with open(equipmen_path, encoding="utf8") as data_reported:
    #             return json.load(data_reported)
    #     elif mode == "w":
    #         with open(equipmen_path, encoding="utf8") as data:
    #             read_data = json.load(data)
    #         if key == "deviceName":
    #             read_data[key] = value
    #             with open(equipmen_path, "w") as data_reported:
    #                 json.dump(read_data, data_reported)
    #         else:
    #             read_data["msg"][key] = str(value)
    #             with open(equipmen_path, "w") as data_reported:
    #                 json.dump(read_data, data_reported)


if __name__ == '__main__':
    read_json = JsonUtil()
    print(read_json.read_sql("select_random_payamount"))
